package cn.edu.zafu.bigdata.x.sxy;

import java.io.IOException;
import java.net.*;
import java.nio.ByteBuffer;
import java.util.Date;

public class UDPClient {
    public static void main(String[] args) throws IOException {
        int prot = 3000;
        DatagramSocket socket = new DatagramSocket();
        InetAddress address = InetAddress.getByName("192.168.16.38"); // 服务端ip
        byte[] sendData = new byte[1024];
        byte[] receiveData = new byte[1024];

        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, address, prot);
        socket.send(sendPacket);

        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        socket.receive(receivePacket);

        long serverTime = ByteBuffer.wrap(receivePacket.getData()).getLong();

        System.out.println("Server Time is" + new Date(serverTime));
        socket.close();
    }
}
